'''
从上到下按层打印二叉树，同一层结点从左至右输出。每一层输出一行。

此题垃圾一次跑通，按行遍历即可
'''
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None
class Solution:
    # 返回二维列表[[1,2],[4,5]]
    def Print(self, pRoot):
        if not pRoot: return []
        res = []
        cur = [pRoot]
        while cur:
            res1 = []
            nextStack = []
            for x in cur:
                res1.append(x.val)
                if x.left: nextStack.append(x.left)
                if x.right: nextStack.append(x.right)
            cur = nextStack
            res.append(res1)
        return res